#encoding: utf-8
'''
Created on 2012-4-24

@author: huangjacky
@copyright: TeamV - Group: WhutOJ
'''

class PyOJRequest(object):
    '''
    web端发送过来的请求的类，以前叫做PyOJData
    '''
    
    def __init__(self, iuid= -1, iqid= -1, ilid= -1, scmdline="", ilimitedtime= -1, ilimitedmem= -1, sInput="", sOutput=""):
        object.__init__(self)
        # 属性
        self.__uid = iuid
        self.__qid = iqid
        self.__lid = ilid
        self.__cmdline = scmdline
        self.__limitedtime = ilimitedtime
        self.__limitedmem = ilimitedmem
        self.__standardinput = sInput
        self.__standardoutput = sOutput
        
    def parse(cls, sparse):
        datas = sparse.split("\r\n")
        if len(datas) == 9:
            request = cls() # 用cls而不直接用PyOJRequest，这样可以解耦
            try:
                request.uid = int(datas[1])
                request.qid = int(datas[2])
                request.lid = int(datas[3])
                request.cmdline = datas[4]
                request.limitedtime = int(datas[5])
                request.limitedmem = int(datas[6])
                request.standardinput = datas[7]
                request.standardoutput = datas[8]
                return request
            except:
                return None
        else:
            return None

    def get_uid(self):
        return self.__uid


    def get_qid(self):
        return self.__qid


    def get_lid(self):
        return self.__lid


    def get_cmdline(self):
        return self.__cmdline


    def get_limitedtime(self):
        return self.__limitedtime


    def get_limitedmem(self):
        return self.__limitedmem


    def get_standardinput(self):
        return self.__standardinput


    def get_standardoutput(self):
        return self.__standardoutput


    def set_uid(self, value):
        self.__uid = value


    def set_qid(self, value):
        self.__qid = value


    def set_lid(self, value):
        self.__lid = value


    def set_cmdline(self, value):
        self.__cmdline = value


    def set_limitedtime(self, value):
        self.__limitedtime = value


    def set_limitedmem(self, value):
        self.__limitedmem = value


    def set_standardinput(self, value):
        self.__standardinput = value


    def set_standardoutput(self, value):
        self.__standardoutput = value
        
    
    parse = classmethod(parse)
    uid = property(get_uid, set_uid, None, None)
    qid = property(get_qid, set_qid, None, None)
    lid = property(get_lid, set_lid, None, None)
    cmdline = property(get_cmdline, set_cmdline, None, None)
    limitedtime = property(get_limitedtime, set_limitedtime, None, None)
    limitedmem = property(get_limitedmem, set_limitedmem, None, None)
    standardinput = property(get_standardinput, set_standardinput, None, None)
    standardoutput = property(get_standardoutput, set_standardoutput, None, None)
        
        
        
